package com.sanyue.dataStructure.TestSort;

import com.sanyue.dataStructure.Sort.Selection;
import com.sanyue.dataStructure.Sort.Sort;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.Arrays;
import java.util.Random;

/**
 * @author sanyue
 * @version 1.0
 * @description: TODO-测试选择排序
 * @date 2022/1/25 下午4:57
 */

@RunWith(JUnit4.class)
public class TestSelectionSort {

    private Integer[] data;

    @Before
    public void setUp() {
        Random random = new Random();
        data = new Integer[10];
        for (int i = 0; i < data.length; i++) {
            data[i] = random.nextInt(10000);
        }
    }

    /**
     * 测试选择排序
     */
    @Test
    public void testSelectionSorted() {
        long start = System.currentTimeMillis();
        Sort sorted = new Selection();
        System.out.println("选择排序前: " + Arrays.toString(data));
        sorted.sort(data);
        System.out.println("选择排序后: " + Arrays.toString(data));
        System.out.println("执行时间: " + (System.currentTimeMillis() - start) + " ms");
    }

}